<template>
	<view class="all page">
		<form @submit="updateSex">
			<radio-group name="sex" class="sex" @change="change">
				<label class="item">
					<radio value="1" :checked="sex==1"/><text>男</text>
				</label>
				<label class="item">
					<radio value="0" :checked="sex==0"/><text>女</text>
				</label>
			</radio-group>
			<button type="primary" class="btn" form-type="submit">提交</button>
		</form>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				sex:"-1"
			}
		},
		methods: {
			change(e){
				this.sex=e.detail.value
			},
			updateSex(){
				uni.showLoading({
						title:"上传中，请稍后"
				})
				let me=this
				let userInfo=uni.getStorageSync("user")[0]
				let token=userInfo.token
				uni.request({
					url:me.root+'/api/updateSex?sex='+me.sex,
					header:{
						"token":token
					},
					success(res) {
						console.log(res)
						if(res.data.err==0){
							uni.setStorageSync("user",res.data.data)
							uni.navigateTo({
								url:"../meInfo/meInfo"
							})
						}else{
							uni.showToast({
								title:res.data.msg
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			}	
		},
		onLoad(params) {
			this.sex=params.sex
		}
	}
</script>

<style scoped>
	.sex{
		background-color: #FFF;
		margin-bottom: 40upx;
		margin-top: 20upx;
	}
	.item{
		display: block;
		padding: 30upx;
		border-bottom: 2px solid #f6f7f2;
	}
	.item:last-child{
		border-bottom: none;
	}
	.btn{
		width: 700upx;
	}
</style>
